package java_demos.java_basic.instance_demos.about_arrary;

import java.util.Arrays;

public class ArraryEleSearchAndSorted {
    public static void main(String[] args) {
        // 创建一个随机数组
        int[] arrary = {2,-10,4,3,-23,33,22,54,-1,0};
        // 对数据进行排序
        Arrays.sort(arrary);
        System.out.println(Arrays.toString(arrary));
        // 使用二分查找进行元素查找
        searchElement(arrary,2);

    }
    private static void searchElement(int[] arrary,int ele){
        int index = Arrays.binarySearch(arrary, ele);
       if(index >= 0){
           System.out.println(ele+" is found at index "+index);
       }else {
           System.out.println(ele+" is not found");
       }
    }
}
